<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>手机号绑定</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" type="text/css" href="../../css/sm.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/normal.css" />
    <link rel="stylesheet" type="text/css" href="../../css/binding.css" />

</head>

<body>
    <div class="page allWarp">
        <div class="content">
            <div class="bigBody">
                <div class="bindbox">
                    <p style="text-align: center;font-size: 1rem;margin-top: 1rem;">身份验证</p>
                    <div class="phoneInput bottomLine" style="margin-top: 1.5rem;">
                        <span class="width100 smallSpan">
                            <input type="tel" placeholder="请输入手机号码" class="width100" v-model="phone">  
                        </span>
                    </div>
                    <div class="phoneInput bottomLine">
                        <span class="width100 smallSpan">
                            <input type="tel" placeholder="请输入验证码" v-model="vcode" style="width: 60%">
                            <button class="obtain generate_code" id="faCode" onclick="generateCode()" >获取验证码</button>
                        </span>
                    </div>
                    <div class="doneBtn" onclick="login()">完成</div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="../../js/zepto.js"></script>
    <script type="text/javascript" src="../../js/sm.min.js"></script>
    <script type="text/javascript" src="../../js/vue.min.js"></script>
    <script type="text/javascript" src="../../js/ajax.js"></script>

    <script type="text/javascript">
        $(function(){
            var w = $(window).width();
            var h = $(window).height();
            $(".bigBody").css("width", w);
            $(".bigBody").css("height", h);
        })
        var codeType = GetQueryString("codeType");  //1,销售 2,客户 3,工人
        var wait = 60;
        if (codeType == 1) {
            var keyN = JSON.parse(getCookie("user_data_one"));
            if (keyN != null) {
                window.location ='../project/myProject.html?role=2';
            }
        } else if(codeType == 2){
            var keyN = JSON.parse(getCookie("user_data_two"));
            if (keyN != null) {
                window.location ='../project/myProject.html?role=1';
            }
        }else if (codeType == 3) {
            var keyN = JSON.parse(getCookie("user_data_three"));
            if (keyN != null) {
                window.location = '../task/taskList.html';
            }
        }
        var demo = new Vue({
            el: '.allWarp',
            data: {
                phone: '',
                vcode: '',
            },
        })
        //  获取验证码
        function generateCode() {
            console.log(1)
            if (!demo.phone) {
                $.toast('请输入手机号');
                return false;
            }
            if (!(/^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/.test(demo.phone))) {
                $.toast('请输入有效的手机号');
                return false;
            }
            var params = {};
            params.phone = demo.phone;
            params.codeType = codeType;
            kfAjaxGet.sendCode(params, function(json) {
                if (json.code == 200) {
                    console.log(2)
                    time();
                } else if (checkcode(json.code)) {

                } else {
                    $.toast(json.message);
                }
            })
        };
        //  获取验证码按钮屏蔽
        function time() {
            console.log(3)
            var code = document.getElementById('faCode');
            if (wait == 0) {
                code.removeAttribute("disabled");
                code.innerHTML = "获取验证码";
                wait = 60;
            } else {
                code.setAttribute("disabled", 'true');
                code.innerHTML = "已发送(" + wait + 's)';
                wait--;
                setTimeout(function() {
                    time()
                }, 1000)
            }
        }

        //  登录
        function login(){
            if (!demo.phone) {
                $.toast('请输入手机号');
                return false;
            }
            if (!(/^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/.test(demo.phone))) {
                $.toast('请输入有效的手机号');
                return false;
            }
            if (!demo.vcode) {
                $.toast('请输入验证码');
                return false;
            }
            var params = {};
            params.phone = demo.phone;
            params.vcode = demo.vcode;
            params.codeType = codeType;
            kfAjaxGet.loginIn(params, function(json) {
                if (json.code == 200) {
                    var userId = json.data.userId;
                    var loginName = json.data.loginName;
                    var customerPhone = demo.phone;
                    var data = {
                        userId: userId,
                        loginName:loginName,
                        customerPhone:customerPhone,
                    }
                    if (codeType == 1) {
                        SetCookie("user_data_one", JSON.stringify(data));
                        window.location ='../project/myProject.html?role=2';
                    } else if(codeType == 2){
                        SetCookie("user_data_two", JSON.stringify(data));
                        window.location ='../project/myProject.html?role=1';
                    }else if (codeType == 3) {
                        SetCookie("user_data_three", JSON.stringify(data));
                        window.location = '../task/taskList.html';
                    }
                } else if (checkcode(json.code)) {

                } else {
                    $.toast(json.message);
                }
            })
        }
    </script>
</body>
</html>